* regressions_formal_bite_industry_ccity.do	JEP	04/11/15
* Does regressions that are in the term paper, for formal workers: RIF4
* Monthly wages
* Exclude some industries
* Do regressions by city - industry
* Cluster by city, so CGM

*************************** Change log ********************************** 

/*
	
*/	

clear 
version 13.1

* Project info
cap project, doinfo
if _rc==198 {
	if c(os)=="Unix" loc master "/home/jperez/AA_Minimum_Wage" 
 else if c(username)=="J16339" loc master "B:\Col_Minimum_Wage"
 else if c(username)=="A15858" loc master "B:\Col_Minimum_Wage"
	else loc master "C:/Users/jorpp/Dropbox (Brown)/Col_Minimum_Wage"
	loc pr = 0
}
else {
	local master "`r(pdir)'"
	local doname "`r(dofile)'"  
 loc pr = 1
	* Project calls
	project, uses("`master'/Data/Source/ocupados_mw.dta")
	* Call programs
	project, relies_on("`master'/Code/Est/sample_choice.do")
	project, relies_on("`master'/Code/Est/build_mw_measures.do")
	project, relies_on("`master'/Code/Est/build_treatment.do")
	project, relies_on("`master'/Code/Est/export_rif.do")
	project, relies_on("`master'/Code/Est/confirmedrun.do")
	project, relies_on("`master'/Code/Est/graph_rif.do")
}
*/


* Call necessary programs. I do not call using project to carry the programs around. I do not put these in the ado/personal folder because they are specific to the project. They are not ado files.
do "`master'/Code/Est/sample_choice.do"
do "`master'/Code/Est/build_mw_measures.do"
do "`master'/Code/Est/build_treatment.do"
do "`master'/Code/Est/export_rif.do"
do "`master'/Code/Est/confirmedrun3.do"
do "`master'/Code/Est/graph_rif.do"


use "`master'/Data/Source/ocupados_mw.dta", clear

* Choose quantiles
glo qtiles "5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90"
* glo qtiles "50"
* Number of bootstraps
glo boot=200

* RIF 4 - Tables numbered 4 in term paper

* Choose sample
mysample rif4sample , hmin(30) hmax(50) sex(0) edadm(65) wage(salario) formal exind(13,29,42)
mysample rif10sample , hmin(30) hmax(50) sex(0) edadm(65) wage(salario) informal exind(13,29,42)
* Build mw measures
mw_measures rif4sample , stub(rif4)
drop salario_real_mensual_med_rif4
mw_measures rif10sample , stub(rif10)
drop salario_real_mensual_med_rif10
* Build treatment
* mytreatment, posts("tq(1999q1)") mw(bite_rif4_ind) wage(salario_mensual_real)

* RIF regressions

* Create estimation results folder if it doesn't already exist
cap mkdir "`master'/Ster"
cap mkdir "`master'/Ster/rif4_new_indcc"
cap mkdir "`master'/Ster/rif4_new_indcc/jointbs/ster"
cap mkdir "`master'/Ster/rif4_new_indcc/jointbs/dta"
cap mkdir "`master'/Ster/rif10_new_indcc"
cap mkdir "`master'/Ster/rif10_new_indcc/jointbs/ster"
cap mkdir "`master'/Ster/rif10_new_indcc/jointbs/dta"

* For these I'm clustering within city, full CGM again


cap drop treat treat2
foreach x in $qtiles {
	di " Percentile `x'"
	loc fw: word 1 of $qtiles
	loc count: word count $qtiles
	di `count'
	loc lw: word `count' of $qtiles
	if `x'==`lw' & `pr'!=0 loc reg="register"
	else loc reg ""
	if `x'==`fw' loc r="replace"
	else loc r="append"
	
	* Panel B. Employment and Bartik Price Variable
	mytreatment, posts("tq(1999q1)") mw(bite_rif4_ind) wage(salario_mensual_real)	
	confirmedrun3, `reg' controls(bartikp1_ex) name(`master'/Ster/rif4_new_indcc/jointbs/ster/reg_emp_bp_tq(1999q1)_bite_salario_mensual_real_50_edom_indcc) rif(rif4B) p(`x') r(`r') sample(rif4sample) fe(i.ccode#i.cactividad_empresa i.time) cluster(ccode)  saving("`master'/Ster/rif4_new_indcc/jointbs/dta/reg_emp_bp_tq(1999q1)_bite_salario_mensual_real_50_edom_indcc_p`x'.dta") 
	drop post treat lw
	
	est use `master'/Ster/rif4_new_indcc/jointbs/ster/reg_emp_bp_tq(1999q1)_bite_salario_mensual_real_50_edom_indcc_p`x'.ster
	loc state=e(state)
	
	est clear
	
	mytreatment, posts("tq(1999q1)") mw(bite_rif10_ind) wage(salario_mensual_real)	
	confirmedrun3, `reg' controls(bartikp1_ex) name(`master'/Ster/rif10_new_indcc/jointbs/ster/reg_emp_bp_tq(1999q1)_bite_salario_mensual_real_50_edom_indcc) rif(rif10B) p(`x') r(`r') sample(rif10sample) fe(i.ccode#i.cactividad_empresa i.time) cluster(ccode) saving("`master'/Ster/rif10_new_indcc/jointbs/dta/reg_emp_bp_tq(1999q1)_bite_salario_mensual_real_50_edom_indcc_p`x'.dta")  state(`state')
	drop post treat lw	
}
/*
foreach x in $qtiles {
	project, creates("`master'/Ster/rif4_new_indcc/jointbs/dta/reg_emp_bp_tq(1999q1)_bite_salario_mensual_real_50_edom_indcc_p`x'.dta")
	project, creates("`master'/Ster/rif10_new_indcc/jointbs/dta/reg_emp_bp_tq(1999q1)_bite_salario_mensual_real_50_edom_indcc_p`x'.dta")
}

*/


